#include <stdio.h>
#include <stdlib.h>

#define NormalCode 0
#define ErrorCode 1

typedef struct StringNode *Position; /* 指针即结点位置 */
struct StringNode {
    char data; /* 存储数据 */
    Position next; /* 链接存储中下一个元素的位置 */
};
typedef struct StringHeadNode *String;
struct StringHeadNode {
    Position head; /* 字符串头指针，初始化为NULL */
    int length; /* 字符串长度 */
};

String InitStr() {
    /* 初始化一个空的字符串 */
    String s;

    s = (String)malloc(sizeof(struct StringHeadNode));
    s->head = NULL;
    s->length = 0;

    return s;
}

/* 算法4-6：字符串插入操作 StrInsert(s, pos, t) */
void StrInsert(String s, int pos, String t) {
    int flag, count;
    Position p, tail;

    flag = NormalCode;
    if (t->length > 0) { /* 若t不是空串 */
        tail = t->head;
        while (tail->next != NULL) { /* 找到t的最后一个元素 */
            tail = tail->next;
        }
        if (s->length > 0) { /* 若s不是空串 */
            p = s->head;
            count = 1;
            while ((p != NULL) && (count < (pos - 1))) {
                /* 找第pos个元素的前一个元素 */
                count++;
                p = p->next;
            }
            if (count == (pos - 1)) { /* 将t插在p的后面 */
                tail->next = p->next;
                p->next = t->head;
            } else if (pos == 1) { /* t插在s的头 */
                tail->next = s->head;
                s->head = t->head;
            } else {
                printf("错误：指定插入位置不存在。\n");
                flag = ErrorCode;
            }
        } else { /* 若s是空串 */
            s = t;
        }
    }
    if (flag != ErrorCode) { /* 正常完成插入 */
        s->length = s->length + t->length;
    }
}
/* 算法4-6 结束 */

String ReadString() {
    String s;
    Position tail;
    char c;

    s = InitStr(); /* 创建空的字符串 */
    s->head = (Position)malloc(sizeof(struct StringNode));
    tail = s->head; /* 先创建临时空头结点 */
    c = getchar();
    while (c != '\n') {
        tail->next = (Position)malloc(sizeof(struct StringNode));
        tail->next->data = c;
        tail = tail->next;
        s->length++;
        c = getchar();
    }
    tail->next = NULL; /* 链表收尾 */
    tail = s->head;
    s->head = s->head->next;
    free(tail); /* 删除临时空头结点 */
    return s;
}

void PrintString(String s) {
    Position p;

    p = s->head;
    while (p != NULL) {
        printf("%c", p->data);
        p = p->next;
    }
}

int main(void) {
    int pos;
    String s, t;

    s = ReadString();
    t = ReadString();
    scanf("%d", &pos);
    StrInsert(s, pos, t);
    PrintString(s);

    return 0;
}